﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Xaml.Behaviors;
using ShanNiang.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ShanNiang.Packing.Behaviors
{
    public  class FullScreenBehavior : Behavior<Window>
    {
        /// <summary>
        /// 是否全屏
        /// </summary>
        public bool IsFullScreen
        {
            get => (bool)GetValue(IsFullScreenProperty);
            set => SetValue(IsFullScreenProperty, value);
        }
        public static readonly DependencyProperty IsFullScreenProperty = DependencyProperty.RegisterAttached("IsFullScreen",
            typeof(bool), typeof(FullScreenBehavior), new PropertyMetadata(false, OnIsFullScreenChanged));

        public static void SetIsFullScreen(Window element, bool value) => element.SetValue(IsFullScreenProperty, value);
        public static bool GetIsFullScreen(Window element) => (bool)element.GetValue(IsFullScreenProperty);

        private static void OnIsFullScreenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is FullScreenBehavior behavior && behavior.AssociatedObject !=null)
            {
                var window = behavior.AssociatedObject;
                if ((bool)e.NewValue)
                {
                    window.Topmost = true;

                    window.WindowState = WindowState.Maximized;
                    //window.WindowStyle = WindowStyle.None;
                }
                else
                {
                    window.Topmost = false;
                    window.Width = 1280;
                    window.Height = 720;
                    window.WindowState = WindowState.Normal;
                    //window.WindowStyle = WindowStyle.None;
                }
            }
        }
    }
}
